#ifndef QRUNNINGHOST_H
#define QRUNNINGHOST_H

#include "../sharedLib/qprojecthost.h"


#include <QScriptEngine>
#include <QMainWindow>

namespace SHAREDLIB
{
    class QPageManager;
    class QUserManager;
    class QBaseKeyBoard;
}

namespace RUNNINGLIB
{
    class QBaseDialogWidget;
    class MyInputPanelContext;
    class QRunningWindow;

    class QRunningHost : public SHAREDLIB::QProjectHost
    {
        Q_OBJECT
    public:
        QRunningHost(QObject *object);
        ~QRunningHost();


        void    setPagemanager(SHAREDLIB::QPageManager *manager);
        void    setUsermanager(SHAREDLIB::QUserManager *manager);
        void    setInputContext(MyInputPanelContext *text);
        void    clear();

        QWidget *getBaseWidget();
        void    setRunningWindow(QRunningWindow* window);

    public slots:
        bool    showPage(const QString &name);
    protected:
        void    reset(SHAREDLIB::QAbstractHost *host);
        void    initGlobalObject();
        void    initWidgetScript(QWidget *wid);
        QScriptEngine *getScriptEngine();
        void    setObjectProperty(QScriptEngine *engine,QScriptValue & value,QAbstractHost* host);

        bool    eventFilter(QObject *, QEvent *);
    protected slots:
        void    pageDestory();
        void    keyboardDestory();

        void    focus_changed(QWidget* old,QWidget* now);
    public slots:
        void    execScript(const QString code,QMap<QString,QString> param);


    public slots:
        void    show_keyboard();
        void    hide_keyboard();
        void    keyboard_send(const QString &key,const QString &text);
    public:
        void    firstScript();
        void    lastScript();

    protected:
        void    set_capslock(bool capslock);
    protected:
        QList<QWidget*>                m_forms;
        QMap<QString,QWidget*>         m_nameToForms;

        QList<QWidget*>                m_keyboards;
        QMap<QString,QWidget*>         m_nameToKeyboards;


        SHAREDLIB::QPageManager *       m_pageManager;
        SHAREDLIB::QUserManager         *m_userManager;
        QWidget*                        m_baseWidget;
        MyInputPanelContext             *m_input_context;

        SHAREDLIB::QBaseKeyBoard        *m_keyboard;
        QRunningWindow                  *m_running_window;
        QWidget                         *m_last_focus_widget;
        bool                             m_capslock;
    };

}
#endif // QRUNNINGHOST_H
